/**
 * 
 */
package fr.upvm.lem3.vm3d.ui.swing.layeredpane;

import java.awt.Color;
import java.awt.Component;

import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.border.Border;

/**
 * customize a Layerredpane.
 * @author Nougouapi
 *   
 */
public class MyLayeredPane extends JLayeredPane {
	
//	private static Color BG_COLOR= new Color(153, 153, 201, 125);
	private static Color BG_COLOR= new Color(0,0,0,0);
	private static Color BORDER_COLOR = Color.BLUE;
  /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static int COMPONENT_POSITION = 0;   // top level position of the Layered panel
	
	/**
	 * 
	 */
	public MyLayeredPane(Color bgCol, Border border , boolean isOpaque){
		setBackground(bgCol);
		setBorder(border);
		setOpaque(isOpaque);
	}
	public MyLayeredPane(){ 
		this(BG_COLOR, BorderFactory.createMatteBorder(1, 1, 1, 1, BORDER_COLOR),true);
	}
	
	
	/**
	 * add a JComponent to this panel
	 * @param component
	 */
  public void addPane(JComponent component){
	  //add new component to the Layered pane on the default layer
	  this.add(component,JLayeredPane.DEFAULT_LAYER,COMPONENT_POSITION);  
	  //move the last added component to the front
	  moveToFront(component);
	  //increment the position variable.
	  COMPONENT_POSITION++;
  }
  /**
   * overrride the dolayout of this component.
   * So all his components will will to it
   */
  
   public void doLayout(){
	   synchronized(getTreeLock()){
		   for(Component c: getComponents()){
			   if(c instanceof JLabel){
				   c.setBounds(Math.abs((int)(getWidth()/2)-(int)(160/2)),
						   			Math.abs((int)(getHeight()/2)-(int)(25/2)),200,25);
			     }else{ 
			    	 c.setBounds(0, 0, getWidth(),getHeight());
			   }
		   }
	   }
   }

/**
 * @return the cOMPONENT_POSITION
 */
public static final int getCOMPONENT_POSITION() {
	return COMPONENT_POSITION;
}

/**
 * @param cOMPONENT_POSITION the cOMPONENT_POSITION to set
 */
public static final void setCOMPONENT_POSITION(int cOMPONENT_POSITION) {
	COMPONENT_POSITION = cOMPONENT_POSITION;
}

}
